package com.hicorp.segment.controller;

import com.hicorp.segment.pojo.po.Annex;
import com.hicorp.segment.service.AnnexService;
import com.hicorp.segment.utils.ResultBean;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/annex/{tableName}")
public class AnnexController {

    private final AnnexService annexService;

    public AnnexController(AnnexService annexService) {
        this.annexService = annexService;
    }

    @PostMapping("/{rowId}/upload")
    public ResultBean<Void> uploadAnnex(@RequestParam("file") MultipartFile file, @PathVariable String tableName, @PathVariable Long rowId) {
        return annexService.uploadAnnex(file, tableName, rowId);
    }

    @GetMapping("/{rowId}")
    public ResultBean<List<Annex>> selectAll(@PathVariable String tableName, @PathVariable Long rowId) {
        return annexService.selectAll(tableName, rowId);
    }

    @PostMapping("/{id}")
    public ResultBean<Long> deleteAnnex(@PathVariable String tableName, @PathVariable Long id, @RequestBody Annex annex) {
        return annexService.deleteSingleAnnex(tableName, id, annex);
    }
}
